const Sequelize = require('sequelize')
const { MYSQL_CONF } = require('../conf/db.js')

const conf = {
    host: MYSQL_CONF.host,
    dialect: 'mysql'
}

//使用连接池
if(process.env.NODE_ENV === 'prod') {
    conf.pool = {
        max: 5,
        min: 0,
        idle: 10000, //如果一个连接池 10S内没有使用，则释放
    }
} else if(process.env.NODE_ENV === 'test') {
    conf.loggin = () => {}
}
 
const seq = new Sequelize(MYSQL_CONF.database, MYSQL_CONF.user, MYSQL_CONF.password, conf)

module.exports = seq